<section class="content-header">
    <h1>
        Danh sách tài khoản người dùng
    </h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo DOMAINAD ?>" ><i class="fa fa-dashboard"></i> Trang chủ</a></li>
        <li class="active"> Danh sách người dùng</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box-header">
                <div class="box-tools">
                    <?php echo $this->Form->create(null, array('url' => DOMAINAD . 'auser/search', 'type' => 'post', 'name' => 'frm_search')); ?>
                    <div class="input-group">
                        <div class="input-group-btn">
                            <a href="<?php echo DOMAINAD; ?>auser/add" class="btn btn-sm btn-success" ><i class="fa fa-fw fa-plus-circle"></i> Thêm mới </a>
                            <a href="#messages" rel="modal" class="btn btn-sm btn-success" ><i class="fa fa-fw fa-question"></i> Trợ giúp </a>
                            <a href="<?php echo DOMAINAD; ?>home" class="btn btn-sm btn-success" ><i class="fa fa-fw fa-times-circle"></i> Đóng </a>
                        </div>
                        <input type="text" name="keyword" value="" class="form-control input-sm pull-right" style="width: 150px;" placeholder="Tìm kiếm">
                        <div class="input-group-btn">
                            <input type="submit" value="Tìm kiếm" class="btn btn-sm btn-default" />
                        </div>
                    </div>
                    <?php echo $this->Form->end(); ?>
                </div>
            </div><!-- /.box-header -->

            <div class="box">
                <div class="box-body table-responsive no-padding">
                    <?php $flash = $this->Session->flash();
                    if(strlen($flash) > 45) {
                        ?>
                        <div class="alert alert-warning alert-dismissablee">
                            <i class="fa fa-warning"></i>
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                            <?php echo $flash?>
                        </div>
                    <?php }?>
                    <table class="table table-hover table-bordered">
                        <thead>
                            <tr>
                                <th width="2%"><input type="checkbox" name="all" id="checkall" /></th>
                                <th width="4%"><?php echo $this->Paginator->sort('User.id', 'Mã'); ?></th>
                                <th width="20%" style="text-align:left;"><?php echo $this->Paginator->sort('User.username', 'Tài khoản'); ?></th>
                                <th width="20%"><?php echo $this->Paginator->sort('User.fullname', 'Tên khách hàng'); ?></th>
                                <th width="20%"><?php echo $this->Paginator->sort('User.email', 'Email'); ?></th>
                                <th width="11%"><?php echo $this->Paginator->sort('User.created', 'Ngày tạo'); ?></th>
                                <th width="12%">Xử lý</th>
                                <th width="10%">Đăng nhập</th>
                            </tr>
                        </thead>
                        <tbody>
                            <form id="frmFilter" method="get">
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td><input class="filter" type="text" name="filter_username" value="<?php echo isset($filter_username) ? $filter_username : ""?>" /></td>
                                    <td><input class="filter" type="text" name="filter_fullname" value="<?php echo isset($filter_fullname) ? $filter_fullname : ""?>" /></td>
                                    <td><input class="filter" type="text" name="filter_email" value="<?php echo isset($filter_email) ? $filter_email : ""?>" /></td>
                                    <td><input class="filter date" type="text" name="filter_created" value="<?php echo isset($filter_created) ? $filter_created : ""?>" /></td>
                                    <td colspan="2">
                                        <button type="submit" class="btn btn-sm btn-success"><i class="fa fa-fw fa-filter"></i> Lọc</button>
                                        <button type="button" id="cancelFilter" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-refresh"></i> Hủy</button>
                                    </td>
                                </tr>
                            </form>
                            <?php echo $this->Form->create(null, array('url' => DOMAINAD . 'auser/action_all', 'type' => 'post', 'name' => 'frm_list')); ?>
                        <?php foreach ($user as $key => $value) {  ?>
                            <tr>
                                <td><input type="checkbox" name="chose_active[<?php echo $value['User']['id']; ?>]" /></td>
                                <td><?php echo $value['User']['id']; ?></td>
                                <td><a href="<?php echo DOMAINAD ?>auser/edit/<?php echo $value['User']['id']; ?>" title="Edit"><?php echo $value['User']['username']; ?></a>  <?php if(date('Y-m-d', strtotime($value['User']['modified'])) == date('Y-m-d')) { ?><img src="<?php echo DOMAINAD ?>images/icons/iconnew.gif" alt="New" /><?php } ?></td>
                                <td style="text-align:left;"><?php echo $value['User']['fullname']; ?></td>
                                <td style="text-align:left;"><?php echo $value['User']['email']; ?></td>
                                <td>
                                    <?php echo date('d-m-Y', strtotime($value['User']['created'])); ?></td>
                                <td>
                                    <a href="<?php echo DOMAINAD ?>auser/copy/<?php echo $value['User']['id']; ?>" title="Copy"><img src="<?php echo DOMAINAD ?>images/icons/copy.png" alt="Copy" /></a>
                                    <a href="<?php echo DOMAINAD ?>auser/edit/<?php echo $value['User']['id']; ?>" title="Edit"><img src="<?php echo DOMAINAD ?>images/icons/pencil.png" alt="Edit" /></a> <a href="javascript:confirmDelete('<?php echo DOMAINAD ?>auser/delete/<?php echo $value['User']['id']; ?>')" title="Delete"><img src="<?php echo DOMAINAD ?>images/icons/cross.png" alt="Delete" /></a>
                                    <?php
                                    if ($value['User']['status'] == 0) {
                                        ?>
                                        <a href="<?php echo DOMAINAD ?>auser/active/<?php echo $value['User']['id']; ?>" title="Kích hoạt" class="icon-5 info-tooltip"><img src="<?php echo DOMAINAD ?>images/icons/Play-icon.png" alt="Kích hoạt" /></a>
                                    <?php
                                    } else {
                                        ?>
                                        <a href="<?php echo DOMAINAD ?>auser/close/<?php echo $value['User']['id']; ?>" title="Đóng" class="icon-4 info-tooltip"><img src="<?php echo DOMAINAD ?>images/icons/success-icon.png" alt="Ngắt kích hoạt" /></a>
                                    <?php
                                    }
                                    ?></td>
                                <td align="center">
                                    <a href="<?php echo DOMAINAD ?>auser/login/<?php echo $value['User']['id']; ?>" class="btn btn-success btn-sm">Login</a>
                                </td>
                            </tr>
                        <?php } ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="8">
                                    <div class="bulk-actions align-left">
                                        <div id="box_action_all" style="float: left; margin-left: 10px;">
                                            <select name="process" id="chose_action_all" class="btn btn-sm btn-default">
                                                <option value="none">Lựa chọn</option>
                                                <option value="active_all">Active</option>
                                                <option value="close_all">Hủy Active</option>
                                                <option value="delete_all">Delete</option>
                                            </select>
                                            <input type="submit" name="submit_action_all" class="btn btn-sm btn-default" value="Thực hiện" />
                                        </div><!--end #box_action_all-->
                                    </div><!--end #bulk-aciton-->

                                    <div class="pagination" style="float: right; margin-right: 10px;">
                                        <?php
                                        if($this->Paginator->counter('{:pages}')>1){
                                            echo $this->Paginator->first('« Đầu ', null, null, array('class' => 'disabled'));
                                            echo $this->Paginator->prev('« Trước ', null, null, array('class' => 'disabled'));
                                            echo $this->Paginator->numbers()." ";
                                            echo $this->Paginator->next(' Tiếp »', null, null, array('class' => 'disabled'));
                                            echo $this->Paginator->last('« Cuối ', null, null, array('class' => 'disabled'));
                                            echo " Page ".$this->Paginator->counter();
                                        }
                                        ?>
                                    </div>
                                    <div class="clear"></div>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                    <?php echo $this->Form->end(); ?>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
    </div>
</section><!-- /.content -->
<script type="text/javascript">
    $(function () {
        $('#cancelFilter').click(function (e) {
            e.preventDefault();
            $(".filter").val("");
            $("#frmFilter").submit();
        });
        $(".date").datepicker({
            format: 'dd-mm-yyyy'
        }).on('changeDate', function(ev) {
            $(this).data('datepicker').hide();
        });
    });
</script>